/**
 * Author: Andrew Shore
 * Date Last Modified: April 14, 2009
 * CSCE 146: Homework 07, PacketAssembler.java
 */
import java.util.Scanner;


public class Packet {
	
	private final String classLabel = "Packet: ";
	static final int DUMMYINT = Integer.MIN_VALUE;
	static final String DUMMYSTRING = "dummy";
	int messageID;
	int packetID;
	int packetCount;
	String payload;
	
	/**
	 * Default constructor for Packet Class
	 */
	public Packet(){
		messageID = 0;
		packetID = 0;
		packetCount = 0;
		payload = "";
	}
	
	/**
	 * Accessors for Packet Class
	 */
	
	public int getMessageID() {
		return messageID;
	}

	
	public int getPacketCount() {
		return packetCount;
	}

	
	public int getPacketID() {
		return packetID;
	}

	
	public String getPayload() {
		return payload;
	}


	/** 
	 * Mutators for Packet Class
	 */
	
	public void setMessageID(int what) {
		messageID = what;
	}

	
	public void setPacketCount(int what) {
		packetCount = what;
	}

	
	public void setPacketID(int what) {
		packetID = what;
	}

	
	public void setPayload(String what) {
		payload = what;
	}
	
	/**
	 * Method readPacket takes a Scanner parameter that is a file of Packets 
	 * and sets the attributes of the Packet and returns itself. Called in
	 * PacketAssembler class, (readPackets method)
	 * 
	 * File is assumed to be in the correct format.
	 */	
	public Packet readPacket(Scanner inFile) {
		
	
		messageID = inFile.nextInt();
			this.setMessageID(messageID);
		
		packetID = inFile.nextInt();
			this.setPacketID(packetID);
		
		packetCount = inFile.nextInt();
			this.setPacketCount(packetCount);
		
		payload = inFile.nextLine();
			this.setPayload(payload);
	
	
		return this;
	}
	
	/**
	 * Method toString returns a String of the instance variables of this class
	 */
	public String toString(){
		String s = "";
		
		s += messageID + "	";
		s += packetID + "	";
		s += packetCount + "	";
		s += payload + "	";
		return s;
	}

}
